var _$ = function (id) {
	return "string" == typeof id ? document.getElementById(id) : id;
};
/** ********page list start********* */
function checkSelectData(){
	var tempSelect=document.getElementsByName("selectCheck");
	if(!(tempSelect==null)){
		for(var i=0;i<tempSelect.length;i++){
			if(tempSelect[i].checked){
				return true;
			}
		}
		return false;
	}else{
		return false;
	} 
}

function checkBooleanSelectData(){
	var tempSelect=document.getElementsByName("selectCheck");
	if(!(tempSelect==null)){
		for(var i=0;i<tempSelect.length;i++){
			if(tempSelect[i].checked){
				return tempSelect[i].value;
			}
		}
		return null;
	}else{
		return null;
	} 
}
function checkMultiSelectData(){
	var ids=null;
	var tempSelect=document.getElementsByName("selectCheck");
	if(!(tempSelect==null)){
		ids="0";
		for(var i=0;i<tempSelect.length;i++){
			if(tempSelect[i].checked){
				ids=ids+","+tempSelect[i].value;
			}
		} 
	}
	return ids;
}

function onSelectChange(obj){
	var tempSelect=document.getElementsByName("selectCheck");
	if(!(tempSelect==null)){
		if(obj.checked){
			for(var i=0;i<tempSelect.length;i++){
				if(!tempSelect[i].checked){
					tempSelect[i].checked=true;
				}
			}
		}else{
			for(var i=0;i<tempSelect.length;i++){
				if(tempSelect[i].checked){
					tempSelect[i].checked=false;
				}
			}
		}
	}
}
function pagePrev(iflag,inumber,message,path){
    var tempstr="<img border=\"0\" src=\"";
    if(iflag){
    	tempstr=tempstr+""+path+"/themes/ext/images/default/grid/page-prev.gif\" onclick=\"pageSetting("+inumber+");\" style=\"cursor:hand;\" ";
    }else{
    	inumber=inumber-1; 
    	tempstr=tempstr+""+path+"/themes/ext/images/default/grid/page-prev-disabled.gif\"";
    }
    tempstr=tempstr+" title=\""+message+"\" ></img>";
    document.write(tempstr);
}
function pageNext(iflag,inumber,message,path){
	var tempstr="<img border=\"0\" src=\"";
    if(iflag){
    	tempstr=tempstr+""+path+"/themes/ext/images/default/grid/page-next.gif\" onclick=\"pageSetting("+inumber+");\" style=\"cursor:hand;\" ";
    }else{
    	inumber=inumber+1; 
    	tempstr=tempstr+""+path+"/themes/ext/images/default/grid/page-next-disabled.gif\"";
    }
    tempstr=tempstr+" title=\""+message+"\" ></img>";
    document.write(tempstr);
}
function pageSetting(inumber){
	_$("page").value=inumber;
	_$("listDataForm").submit();
}
function goOnclick(){
	_$("listDataForm").submit();
}
function pageOnclick(){
	var page=_$("page").value;
	var totalPage=_$("totalPage").value;
	var reg = /^[1-9]+[0-9]*]*$/;
	if (!reg.test(page)) {
		 alert("请输入正整数");
		 _$("page").focus();  
		 return false;  
	} 
	if(page>totalPage){
		alert("不能大于总的页数");
		 _$("page").focus();  
		 return false; 
	}
}
function pageSizeOnclick(){
	var pageSize=_$("pageSize").value;
	var reg = /^[1-9]+[0-9]*]*$/;
	if (!reg.test(pageSize)) {
		 alert("请输入正整数");
		 _$("pageSize").focus();  
		 return false;  
	}
}
function writePage(messages,path,currentPage,totalPage,pageSize){
	if(totalPage>1){
		var prePage=parseInt(currentPage,10)-1;
		var nextPage=parseInt(currentPage,10)+1;
		if(currentPage==1){
			pageFirst(false,messages[0],path);
			pagePrev(false,1,messages[1],path);
			var tempstr=messages[8]+"<input type=\"text\" value=\""+currentPage+"\" size=\"2\"  onchange=\"javascript:pageOnclick();\" name=\"page\" id=\"page\">"+messages[4];
			document.write(tempstr);
			pageNext(true,nextPage,messages[2],path);
			pageLast(true,totalPage,messages[3],path);
			tempstr="&nbsp;&nbsp;&nbsp;&nbsp;"+messages[5]+"<input type=\"text\" value=\""+pageSize+"\" size=\"2\" onchange=\"javascript:pageSizeOnclick();\" name=\"pageSize\" id=\"pageSize\">"+messages[7];
			tempstr=tempstr+"&nbsp;"+messages[6]+":<input type=\"text\" readonly=\"readonly\" size=\"2\" value=\""+totalPage+"\" name=\"totalPage\" id=\"totalPage\">"+messages[4];
			document.write(tempstr);
		}else if(currentPage==totalPage){
			pageFirst(true,messages[0],path);
			pagePrev(true,prePage,messages[1],path);
			var tempstr=messages[8]+"<input type=\"text\" value=\""+currentPage+"\" size=\"2\" onchange=\"javascript:pageOnclick();\" name=\"page\" id=\"page\">"+messages[4];
			document.write(tempstr);
			pageNext(false,currentPage,messages[2],path);
			pageLast(false,totalPage,messages[3],path);
			tempstr="&nbsp;&nbsp;&nbsp;&nbsp;"+messages[5]+"<input type=\"text\" value=\""+pageSize+"\" size=\"2\" onchange=\"javascript:pageSizeOnclick();\" name=\"pageSize\" id=\"pageSize\">"+messages[7];
			tempstr=tempstr+"&nbsp;"+messages[6]+":<input type=\"text\" readonly=\"readonly\" size=\"2\" value=\""+totalPage+"\" name=\"totalPage\" id=\"totalPage\">"+messages[4];
			document.write(tempstr);
		}else{
			pageFirst(true,messages[0],path);
			pagePrev(true,prePage,messages[1],path);
			var tempstr=messages[8]+"<input type=\"text\" value=\""+currentPage+"\" size=\"2\" onchange=\"javascript:pageOnclick();\" name=\"page\" id=\"page\">"+messages[4];
			document.write(tempstr);
			pageNext(true,nextPage,messages[2],path);
			pageLast(true,totalPage,messages[3],path);
			tempstr="&nbsp;&nbsp;&nbsp;&nbsp;"+messages[5]+"<input type=\"text\" value=\""+pageSize+"\" size=\"2\" onchange=\"javascript:pageSizeOnclick();\" name=\"pageSize\" id=\"pageSize\">"+messages[7];
			tempstr=tempstr+"&nbsp;"+messages[6]+":<input type=\"text\" readonly=\"readonly\" size=\"2\" value=\""+totalPage+"\" name=\"totalPage\" id=\"totalPage\">"+messages[4];
			document.write(tempstr);
		}
		var tempstr="&nbsp;&nbsp;<input type=\"button\" style=\"background: #C0C0C0 url('../images/go.gif') no-repeat center;width: 19px;\" value=\"go\" size=\"2\" onClick=\"javascript:goOnclick();\" name=\"go\" id=\"go\">&nbsp;&nbsp;&nbsp;";
		document.write(tempstr); 
	}else{
		pageFirst(false,messages[0],path);
		pagePrev(false,1,messages[1],path);
		var tempstr=messages[8]+"<input type=\"text\" value=\""+currentPage+"\" size=\"2\" onchange=\"javascript:pageOnclick();\" name=\"page\" id=\"page\">"+messages[4];
		document.write(tempstr);
		pageNext(false,1,messages[2],path);
		pageLast(false,totalPage,messages[3],path);
		tempstr="&nbsp;&nbsp;&nbsp;&nbsp;"+messages[5]+"<input type=\"text\" value=\""+pageSize+"\" size=\"2\" onchange=\"javascript:pageSizeOnclick();\" name=\"pageSize\" id=\"pageSize\">"+messages[7];
		tempstr=tempstr+"&nbsp;"+messages[6]+":<input type=\"text\" readonly=\"readonly\" size=\"2\" value=\""+totalPage+"\" name=\"totalPage\" id=\"totalPage\">"+messages[4];
		document.write(tempstr);
		tempstr="&nbsp;&nbsp;<input type=\"button\" style=\"background: #C0C0C0 url('../images/go.gif') no-repeat center;width: 19px;\" value=\"go\" size=\"2\" onClick=\"javascript:goOnclick();\" name=\"go\" id=\"go\">&nbsp;&nbsp;&nbsp;";
		document.write(tempstr); 
	}
}
function dataRequire(arg){
	return arg==null?false:true;
}
function variableCheck(){
	var formObj=_$("saveForm");
	
	var formElements=formObj.elements;
	var  data="0";
	for(var iCount=0;iCount<formElements.length;iCount++){
		var type=formElements[iCount].type.toLowerCase();
		if(type!="button"){
			var dataRequire=formElements[iCount].getAttribute("dataRequire");
			if(!(dataRequire==null||dataRequire=="")){
				if(formElements[iCount].value==""){
					alert();
					formElements[iCount].focus();
				}
			}
			if("text".indexOf(type)>=0){
				
			}
		}
	}
}


function pageLast(iflag,inumber,message,path){
	var tempstr="<img border=\"0\" src=\"";
    if(iflag){
    	tempstr=tempstr+""+path+"/themes/ext/images/default/grid/page-last.gif\" onclick=\"pageSetting("+inumber+");\" style=\"cursor:hand;\"";
    }else{
    	tempstr=tempstr+""+path+"/themes/ext/images/default/grid/page-last-disabled.gif\"";
    }
    tempstr=tempstr+" title=\""+message+"\" ></img>";
    document.write(tempstr);
}
function pageFirst(iflag,message,path){
	var tempstr="<img border=\"0\" src=\"";
    if(iflag){
    	tempstr=tempstr+""+path+"/themes/ext/images/default/grid/page-first.gif\" onclick=\"pageSetting(1);\" style=\"cursor:hand;\"";
    }else{
    	tempstr=tempstr+""+path+"/themes/ext/images/default/grid/page-first-disabled.gif\"";
    }
    tempstr=tempstr+" title=\""+message+"\" ></img>";
    document.write(tempstr);    
}

function pageImageClick(inumber){
    
}
/** ********page list end********* */ 
function saveFunction(){
	extendCustomer();
	alert(_$('feedbackKeyAndValue').value);
	_$("saveForm").submit();
}
function extendCustomer(){
	var formObj=_$('saveForm');
	var formElements=formObj.elements;
	var formKeyAndValue="";
	for(var iCount=0;iCount<formElements.length;iCount++){ 
		if(formElements[iCount].getAttribute("name").indexOf(".id")>0){
			var arrays=formElements[iCount].getAttribute("id").split(".");
			if(arrays.length>1){
				if(arrays[1]=="id"){
					formKeyAndValue="{ID;;;;;"+encodeURIComponent(formElements[iCount].getAttribute("value"));
					break;
				}
			}
		}
	}
	
	for(var iCount=0;iCount<formElements.length;iCount++){
		if(formElements[iCount].getAttribute("extend")=="true"){ 
			formKeyAndValue=formKeyAndValue+"::::::::::"+formElements[iCount].getAttribute("dataType")+";;;;;"+formElements[iCount].getAttribute("name")+";;;;;"+encodeURIComponent(formElements[iCount].value);
		}
	}
	formKeyAndValue=formKeyAndValue+"}";
	_$('feedbackKeyAndValue').value=formKeyAndValue;
} 

function _$name(obj){
	return document.getElementsByName(obj);
}
/** ********calendar event start********* */
function disableselect(checked){
	if (checked){
		_$('enddatetr').style.display="none";				
	 	_$name("voa.value(Event).field(StartDate)")[0].disabled="";
	 	_$name("voa.value(Event).field(EndDate)")[0].disabled="disabled";
		var value=_$name("voa.value(Event).field(StartDate)")[0].value;
		_$name("voa.value(Event).field(EndDate)")[0].value=value;
		_$name("voa.value(Event).field(StartTime_hour)")[0].disabled="disabled";
	 	_$name("voa.value(Event).field(StartTime_minute)")[0].disabled="disabled";
		_$name("voa.value(Event).field(EndTime_hour)")[0].disabled="disabled";
	 	_$name("voa.value(Event).field(EndTime_minute)")[0].disabled="disabled";
		_$name("voa.value(Event).field(AllDay)")[0].value="true";
	}else{
		_$('enddatetr').style.display="block";
	 	_$name("voa.value(Event).field(StartDate)")[0].disabled="";
	 	_$name("voa.value(Event).field(EndDate)")[0].disabled="";
		_$name("voa.value(Event).field(StartTime_hour)")[0].disabled="";
	 	_$name("voa.value(Event).field(StartTime_minute)")[0].disabled="";
		_$name("voa.value(Event).field(EndTime_hour)")[0].disabled="";
	 	_$name("voa.value(Event).field(EndTime_minute)")[0].disabled="";
		_$name("voa.value(Event).field(AllDay)")[0].value="false";
	}
}

function isDateTimeTrueAndSubmit(formName,messages){
 	var startdate=_$('startdate').value;	
	var enddate=_$('enddate').value;
	var starthour=_$name("voa.value(Event).field(StartTime_hour)")[0].value;
	var endhour=_$name("voa.value(Event).field(EndTime_hour)")[0].value;
	var allday=_$name("voa.value(Event).field(AllDay)")[0].value;
	var today=new Date();
	var stt = startdate.split("-");
	var startday = new Date(stt[0],stt[1]-1,stt[2],starthour,0,0);
	var sy = startday.getYear();
	var sm = startday.getMonth();
	var sd = startday.getDate();
	var st=startday.getTime();
	
	var ett = enddate.split("-");
	var endday = new Date(ett[0],ett[1]-1,ett[2],endhour,0,0);
	var ey = endday.getYear();
	var em = endday.getMonth();
	var ed = endday.getDate();
	var et=endday.getTime(); 
	var MinMilli = 1000 * 60
	var HrMilli = MinMilli * 60
	var DyMilli = HrMilli * 24
	if(allday!="true"){
		if(st>et){	// <1bean:message key='endDate-is-not-smaller-startDate'/>
			alert(messages[0]);		
		}else{	
			if(et-st>DyMilli*2){// <1bean:message
								// key='only-can-create-two-day-canlendar'/>
				alert(messages[1]);			
			}else{
				if((sy==ey&&sm==em&&sd==ed)&&(starthour-endhour>0)){
					// <1bean:message key='endHour-is-not-smaller-startHour'/>
					alert(messages[2]);
				}else{
					ajax_search_list_submit_new(formName,'');
				}
			}
		}	
	}else{
		ajax_search_list_submit_new(formName,'');
	}
	
 }
function ajax_search_list_submit_new(_id,addtionPostData) {	
	ajaxAnywhere.formId =_id;
	ajaxAnywhere.submitAJAX(addtionPostData);
}
/** ********calendar event end********* */
function showPageLoadingMessage(message,imageUrl){
	var div = document.getElementById("page_loading_div");
    if (div == null) {
        div = document.createElement("DIV");

        document.body.appendChild(div);
        div.id = "page_loading_div";

        div.innerHTML = "<img src=\""+imageUrl+"/images/ajax_loading.gif\" /><br/>"+message;
        div.style.textAlign= "center";
        div.style.padding="30px, 40px";
        div.style.position = "absolute";
        div.style.border = "1px solid #369";
        div.style.color = "#369";
        div.style.backgroundColor = "#fff";
        div.style.fontFamily = "Arial";
        div.style.fontWeight = "bold";
        div.style.fontSize = "1em";
    }
	div.style.top  = ((document.body.offsetHeight)/2 - 30) + "px";
    div.style.left = ((document.body.offsetWidth)/2 - 40) + "px";

	div.style.display = "";
}
function hiddenPageLoadingMessage(){
	 var div = document.getElementById("page_loading_div");
	    if (div != null)
	        div.style.display = "none";
}
function ShowMessageAlert(sConfirm) {
	try {
		$("AlertInfo").childNodes[1].innerHTML = "&nbsp;" + sConfirm;
		$("AlertInfo").style.display = "";
		setTimeout('showAlertInfo(100)', 1000);
	} catch (e) {
	}
}
function showAlertInfo(iFilter) {
	eval("document.getElementById(\"AlertInfo\").style.filter=\"Alpha(Opacity=" + iFilter+ ")\";");
	iFilter = iFilter - 5;
	if (iFilter < 10) {
		hiddenAlertInfo();
		$("AlertInfo").style.filter = "progid:DXImageTransform.Microsoft.Shadow(color=#777777, Direction=135, Strength=3)";
		return;
	}
	setTimeout('showAlertInfo(' + iFilter + ')', 60);
}
function hiddenAlertInfo() {
	$("AlertInfo").style.className = "tooltip";
	$("AlertInfo").style.filter = "progid:DXImageTransform.Microsoft.Shadow(color=#777777, Direction=135, Strength=3)";
	$("AlertInfo").style.display = "none";
} 

function collectObjDataToString(obj){
	var objT =_$(obj);
	var tstr="";
	for(var i=0;i<objT.options.length;i++){
		tstr=tstr+objT.options[i].value+"::";
	}
	if(tstr!=""){
		tstr=tstr+"0";
		return tstr;
	}else{
		return "";
	}
}
function move(from,to){
	var formObj=_$(from);
	var toObj=_$(to);
	if(formObj.value==""){
			alert("please choose data!");
	}
	for(var i=0;i<formObj.options.length;i++){
		if(formObj.options[i].selected){
			var ooption=document.createElement("option");
			ooption.text=formObj.options[i].text;
			ooption.value=formObj.options[i].value;
			var iflag=false;
			for(var j=0;j<toObj.options.length;j++){
				if(toObj.options[j].value==formObj.options[i].value){
				iflag=true;
				break;
				}
				
			}
			if(!iflag){
				if(document.all){
					toObj.add(ooption);
				}else
				toObj.appendChild(ooption);
			}
		}
	}
	for(var i=0;i<formObj.options.length;i++){
		if(formObj.options[i].selected){ 
			if(document.all){
				formObj.remove(i);
			}else
				formObj.removeChild(formObj.options[i]);
			break;
		}
	}
}
function moveAll(from,to){
	var formObj=_$(from);
	var toObj=_$(to);
	for(var i=0;i<formObj.options.length;i++){
		var ooption=document.createElement("option");
		ooption.text=formObj.options[i].text;
		ooption.value=formObj.options[i].value;
		var iflag=false;
		for(var j=0;j<toObj.options.length;j++){
			if(toObj.options[j].value==formObj.options[i].value){
			iflag=true;
			break;
			}
			
		}
		if(!iflag){
				if(document.all){
					toObj.add(ooption);
				}else
				toObj.appendChild(ooption);
			} 
	}
	for(var i=formObj.options.length-1;i>=0;i--){ 
		if(document.all){
			formObj.remove(i);
		}else
			formObj.removeChild(formObj.options[i]); 
	}
}
dwr.util.useLoadingMessage=function(message){
	var loadingMessage;
	if (message) loadingMessage = message;
	else loadingMessage = '正在加载，请稍候...';
	dwr.engine.setPreHook(function() {
	    var disabledZone  = dwr.util.byId('disabledZone');
	    if (!disabledZone ) { 
	    	disabledZone = document.createElement('div');
	        disabledZone.setAttribute('id', 'disabledZone');
	        disabledZone.style.position = "absolute";
	        disabledZone.style.zIndex = "1000";
	        disabledZone.style.left = "0px";
	        disabledZone.style.top = "0px";
	        disabledZone.style.width = "100%";
	        disabledZone.style.height = "100%";
	        document.body.appendChild(disabledZone);

	        var div  = document.createElement('div');
	        div.setAttribute('id', 'messageZone');
	        div.style.top  = ((document.body.offsetHeight)/2 - 30) + "px";
	        div.style.left = ((document.body.offsetWidth)/2 - 40) + "px";
	        div.style.textAlign= "center";
	        div.style.padding="30px, 40px";
	        div.style.position = "absolute";
	        div.style.border = "1px solid #369";
	        div.style.color = "#369";
	        div.style.backgroundColor = "#fff";
	        div.style.fontFamily = "Arial";
	        div.style.fontWeight = "bold";
	        div.style.fontSize = "1em";  
	        disabledZone.appendChild(div);
	        dwr.util.byId('messageZone').innerHTML = "<img src=\"images/ajax_loading.gif\" /><br/>"+loadingMessage;
	        dwr.util._disabledZoneUseCount = 1;
	    }else{
	    	dwr.util.byId('messageZone').innerHTML = "<img src=\"images/ajax_loading.gif\" /><br/>"+loadingMessage;
	    	disabledZone .style.visibility = 'visible';
	        dwr.util._disabledZoneUseCount++; 
	    }
	}); 
	dwr.engine.setPostHook(function() {
	    dwr.util._disabledZoneUseCount--;
	    if (dwr.util._disabledZoneUseCount == 0) {
	      dwr.util.byId('disabledZone').style.visibility = 'hidden';
	    }
	  });
};
